/* eslint-disable no-case-declarations */
export const regPhone = curVal => {
    const reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[56]|17[0135678]|18[0-9]|19[189])\d{8}$/;
    const bool = reg.test(curVal);
    return bool ? '' : '手机号码格式不正确';
};

export const regVerification = curVal => {
    const reg = /^\d{6}$/;
    const bool = reg.test(curVal);
    return bool ? '' : '验证码不正确';
};

export const regSum = curVal => {
    const reg = /^-?[1-9][0-9]?.?[0-9]*$/;
    const bool = reg.test(curVal);
    return bool ? '' : '请输入正确数量';
};

export const regPwd = curVal => {
    const reg = /^[A-Za-z0-9_]{6,20}$/;
    const bool = reg.test(curVal);
    return bool ? '' : '密码为6-20位，可包含数字和字母';
};

export const regPwd2 = (curVal, curVal2) => {
    const bool = curVal == curVal2;
    return bool ? '' : '两次登录密码输入不同';
};

export const regTradePwd = (curVal, pwd) => {
    pwd = pwd | null;

    const reg = /^(\w){6,20}$/;
    const bool = reg.test(curVal);
    if (!curVal) {
        return '二级密码不能为空';
    }
    if (curVal == pwd) {
        return '二级密码和登录密码不能相同';
    }
    return bool ? '' : '二级密码格式不正确';
};

export const regTradePwd2 = (curVal, curVal2) => {
    const bool = curVal === curVal2;
    return bool ? '' : '两次二级密码输入不同';
};



export const regSubmit = verify => {
    const pwd = verify.pwd || '';
    const PayPwd = verify.pwdtow || '';
    for (let i in verify) {
        switch (i) {
            case 'phone':
                const rPhone = regPhone(verify[i]);
                if (rPhone) return rPhone;
                break;
            case 'authCode':
                const rVerification = regVerification(verify[i]);
                if (rVerification) return rVerification;
                break;
            case 'pwd':
                const rPwd = regPwd(verify[i]);
                if (rPwd) return rPwd;
                break;
            case 'pwd2':
                const rPwd2 = regPwd2(verify[i], pwd);
                if (rPwd2) return rPwd2;
                break;
            case 'pwdtow':
            case 'pwdtwo':
                const rTradePwd = regTradePwd(verify[i], pwd);
                if (rTradePwd) return rTradePwd;
                break;
            case 'pwdtow2':
                const rTradePwd2 = regTradePwd2(verify[i], PayPwd);
                if (rTradePwd2) return rTradePwd2;
                break;
            case 'num':
                const rSum = regSum(verify[i]);
                if (rSum) return rSum;
                break;
            default:
        }
    }
};